<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/11/1
 * Time: 9:38 AM
 */

namespace app\admin\controller;


use think\Request;

class ActivityOrder extends Auth
{
    /**
     * @purpose 通过团期获取订单
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function orderByGroupStage (Request $request)
    {
        $group_stage_id     = $request->get('group_stage_id', '');
        return \app\admin\logic\ActivityOrder::orderByGroupStage($group_stage_id);
    }
    /**
     * @purpose 取消已支付订单
     * @param Request $request
     * @return array
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelByPay (Request $request)
    {
        $order_no       = $request->post('order_no', '');
        $reason         = $request->post('reason', '');
        return \app\admin\logic\ActivityOrder::cancelByPay($order_no, $reason);
    }
    /**
     * @purpose 未支付时取消订单
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelByNotPay (Request $request)
    {
        $order_no       = $request->post('order_no', '');
        $reason         = $request->post('reason', '');
        return \app\admin\logic\ActivityOrder::cancelByNotPay($order_no, $reason);
    }
    /**
     * @purpose 取消出行人并退款
     * @param Request $request
     * @return array
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelTravelByPay (Request $request)
    {
        $attach_id  =    $request->post('attach_id');
        $reason     =    $request->post('reason');
        return \app\admin\logic\ActivityOrder::cancelTravelByPay($attach_id, $reason);
    }
    /**
     * @purpose 订单未支付时取消出行人
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelTravelByNotPay (Request $request)
    {
        $attach_id  =    $request->post('attach_id');
        $reason     =    $request->post('reason');
        return \app\admin\logic\ActivityOrder::cancelTravelByNotPay($attach_id, $reason);
    }
    /**
     * @purpose 编辑出行人
     * @param Request $request
     * @return array
     */
    public function editAttach (Request $request)
    {
        $data = $request->post();
        return \app\admin\logic\ActivityOrder::editAttach($data);
    }
    /**
     * @purpose 获取订单列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function items (Request $request)
    {
        $status     = $request->get('status', 1);
        $page       = $request->get('page', 1);
        $size       = $request->get('size', 20);
        return \app\admin\logic\ActivityOrder::items($status, $page, $size);
    }

    /**
     * @purpose 获取订单详情
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function detail (Request $request)
    {
        $order_no       = $request->get('order_no', '');
        return \app\admin\logic\ActivityOrder::detail($order_no);
    }
}